﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Text;

namespace ProjectBase.Utils
{
    public class CSession
    {
        public CSession() { }


        /// <summary>
        /// Thiet lap gia tri session theo key
        /// </summary>
        /// <param name="sessName"></param>
        /// <param name="sessVal"></param>
        public static void SetSessionValue(String sessName, String sessVal)
        {
            HttpContext.Current.Session[sessName] = sessVal;
        }

        public static void SetSessionValue(String sessName, object sessVal)
        {
            HttpContext.Current.Session[sessName] = sessVal;
        }


        /// <summary>
        /// Lay gia tri session theo key
        /// </summary>
        /// <param name="sessName"></param>
        /// <returns></returns>
        public static object GetSessionValue(String sessName)
        {
            //string valSession = "";

            //if (HttpContext.Current.Session[sessName] != null)
            //{
            //    valSession = HttpContext.Current.Session[sessName].ToString();
            //}

            return HttpContext.Current.Session[sessName];
        }

        /// <summary>
        /// Lấy giá giá của session theo tên
        /// </summary>
        /// <param name="sessName"></param>
        /// <param name="defaultVal"></param>
        /// <returns></returns>
        public static String GetValue(String sessName, String defaultVal)
        {
            if (HttpContext.Current.Session[sessName] != null)
            {
                defaultVal = HttpContext.Current.Session[sessName].ToString();
            }

            return defaultVal;
        }

        /// <summary>
        /// Kiem tra session da ton tai
        /// </summary>
        /// <param name="sessName"></param>
        /// <returns></returns>
        public static bool CheckSession(String sessName)
        {
            if (HttpContext.Current.Session[sessName] == null || HttpContext.Current.Session[sessName].ToString() == "")
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
